package com.mallcai.bigdata.ladon.service.report.impl.handler.support.rule;


import com.mallcai.bigdata.ladon.utils.CollectionUtils;

import java.util.Collection;
import java.util.Collections;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-22 09:36
 */
public abstract class AbstractCollectionRuleOperator extends AbstractNotNullRuleOperator{

    @Override
    public final boolean test(Object obj1, Object obj2) {
        if (!super.test(obj1, obj2)){
            return false;
        }
        if (!CollectionUtils.isCollection(obj1)){
            obj1 = Collections.singletonList(obj1);
        }
        if (!CollectionUtils.isCollection(obj2)){
            obj2 = Collections.singletonList(obj2);
        }
        return innerTest((Collection)obj1, (Collection)obj2);
    }

    protected abstract boolean innerTest(Collection obj1, Collection obj2);

}
